package com.dell.chen.dao.impl;

import com.dell.chen.dao.UserDao;
import com.dell.chen.pojo.Users;

/**
 * @author ：ChenwithIU
 * @date ：Created in 2020/11/24 16:24
 */
public class UserDaoImpl extends BaseDao implements UserDao {

    @Override
    public Users queryUserByUsername(String username) {
        String sql = "select `id`,`username`,`password`,`name`,`gender`,`age`,`phone`,`address`,`img_path`" +
                "  from f_user where username = ?";
        return queryForOne(Users.class,sql,username);
    }

    @Override
    public Users queryUserByUsernameAndPassword(String username, String password) {
        String sql = "select `id`,`username`,`password`,`name`,`gender`,`age`,`phone`,`address`,`img_path`" +
                "  from f_user where username = ? and password=?";
        return queryForOne(Users.class,sql,username,password);
    }

    @Override
    public int updateUser(Users users) {
        String sql = "update f_user set `name`=?,`age`=?,`gender` = ?,`phone`=? ,`password` = ?, `address`=? ,`img_path`=? where username = ?";
        return update(sql,users.getName(),users.getAge(),users.getGender(),users.getPhone(),users.getPassword(),users.getAddress(),users.getImg_path(),users.getUsername());
    }

    @Override
    public int saveUser(Users users) {
        String sql = "insert into f_user(`username`,`password`,`name`,`gender`,`age`,`phone`,`address`,`img_path`)" +
                "values(?,?,?,?,?,?,?,?)";
        return update(sql,users.getUsername(),users.getPassword(),users.getName(),users.getGender(),users.getAge(),users.getPhone(),users.getAddress(),users.getImg_path());
    }
}
